//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#ifndef Green_RecoveryAddressGenerator_H
#define Green_RecoveryAddressGenerator_H

#include "Defines.h"
#include "Enums.h"
#include "Object.h"
#include ARCH_ENUM_HEADER

namespace Green {

  class Generator;
  class GenPageRequest;
  class VmMapper;

  /*!
    \class RecoveryAddressGenerator
    \brief Class to generate addresses to use for recovery operations such as in fault handlers or register reloading.
  */
  class RecoveryAddressGenerator : public Object {
  public:
    explicit RecoveryAddressGenerator(const Generator* pGenerator); //!< Constructor
    SUPERCLASS_DESTRUCTOR_DEFAULT(RecoveryAddressGenerator); //!< Destructor
    ASSIGNMENT_OPERATOR_ABSENT(RecoveryAddressGenerator);

    const std::string ToString() const override { return Type(); } //!< Return a string describing the current state of the Object.

    uint64 GenerateAddress(cuint64 align, cuint64 size, cbool isInstr, const EMemAccessType memAccessType) const; //!< Generate an address.
  protected:
    COPY_CONSTRUCTOR_DEFAULT(RecoveryAddressGenerator);
    virtual const GenPageRequest* CreateGenPageRequest(cbool isInstr, const EMemAccessType memAccessType) const = 0; //!< Create a GenPageRequest instance.
    VmMapper* GetCurrentVmMapper() const; //!< Get the active VmMapper instance.
  private:
    const Generator* mpGenerator; //!< Generator
  };

}

#endif  // Green_RecoveryAddressGenerator_H
